/*
 * Copyright 2010 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.websocket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.util.Set;

/**
 * An interface for different WebSocket handshake implementations.
 */
public interface WebSocketHandshake {

  /**
   * Initiate a client-side WebSocket connection.
   * 
   * Note that the caller is required to enforce any DoS provisions and setup
   * a connection to the ultimate server via a proxy if required.
   * 
   * @param in
   * @param out
   * @param extensions
   * @param uri
   * @param origin
   * @return a WebSocket instance for the established connection
   * @throws IOException if the connection could not be established
   */
  WebSocket clientHandshake(InputStream in, OutputStream out,
      Set<Extension> extensions, URI uri, String origin) throws IOException;

  /**
   * Initiate a server-side WebSocket connection.
   * 
   * Note that the caller is required to enforce any DoS provisions.
   * 
   * @param in
   * @param out
   * @param extensions
   * @param port
   * @return a WebSocket instance for the established connection
   * @throws IOException if the connection could not be established
   */
  WebSocket serverHandshake(InputStream in, OutputStream out,
      Set<Extension> extensions, int port) throws IOException;
}
